﻿(function() {
function addCSS(name) {
  var css = document.createElement('link');

  css.setAttribute('rel', 'stylesheet');
  css.setAttribute('type', 'text/css');
  css.setAttribute('href', name);
  css.setAttribute('media', 'screen');

  document.head.appendChild(css);
}

function addJS(name, callback) {
  var script = document.createElement('script');

  script.setAttribute('id', name);
  script.setAttribute('type', 'text/javascript');
  script.setAttribute('src', name);
  script.setAttribute('charset', 'UTF-8');
  
  if (callback && typeof(callback) == 'function') {
    script.addEventListener('load', callback, true);
  }

  document.head.appendChild(script);
  
  return script;
}

//---------------------------------------------------------

var mjs_vocatube_url = location.href.substr(0,location.href.lastIndexOf("/")+1);

var mjs_core_name  = mjs_vocatube_url + 'media-js-core.js';
var mjs_css_name   = mjs_vocatube_url + 'media-js.css';

var core_scr = document.getElementById(mjs_core_name);

// add mediajs script and css to page, if not already
if (!core_scr){
    addCSS(mjs_css_name);
    core_scr = addJS(mjs_core_name);
}

try { mjsSetup(); } catch(e) {
  core_scr.addEventListener('load', function() { mjsSetup(); });
}

})();
